package com.woniu.user.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniu.user.infra.model.UserVipRelation;
import com.woniu.user.infra.mapper.UserVipRelationMapper;
import com.woniu.user.service.UserVipRelationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.user.service.dto.UserVipRelationDto;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户会员记录表 服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2022-11-26
 */
@Service
public class UserVipRelationServiceImpl extends ServiceImpl<UserVipRelationMapper, UserVipRelation> implements UserVipRelationService {
    //查看用户的会员卡
    @Override
    public List<UserVipRelationDto> getUserVipCard(Integer userId) {
        //TODO 判断是否过期，过期不展示
        List<UserVipRelation> cardInfo = list(new QueryWrapper<UserVipRelation>().eq("user_id", userId).orderByAsc("discount"));
        List<UserVipRelationDto> userVipRelationDtos = BeanUtil.copyToList(cardInfo, UserVipRelationDto.class);
        return userVipRelationDtos;
    }

    @Override
    public void setPayOk(String num) {
        System.out.println("==================================================");
        UserVipRelation cardInfo =getOne(new QueryWrapper<UserVipRelation>().eq("card_num", num));
        cardInfo.setStatus("NORMAL");
        updateById(cardInfo);
    }
}
